<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class ImageModel extends Model
{
    protected $table = 'image';

    //插入幻灯片
    public function insertImage($data) {
        $res = self::insert($data);
        return $res;
    }

    //查询所有幻灯片
    public function getImages() {
        $res = self::get()->toArray();
        return $res;
    }

    //获取一条幻灯片
    public function getImage($id) {
        $res = self::find($id)->toArray();
        return $res;
    }

    //更新幻灯片
    public function upImages($id , $data) {
        $res = self::where('id' , $id)->update($data);
        return $res;
    }

    //删除幻灯片
    public function delImage($id) {
        $res = self::destroy($id);
        return $res;
    }

    //获取幻灯片（排序）
    public function getImagesBySort() {
        $res= self::select('url' , 'img_url')
                    ->orderBy('sort' , 'asc')
                    ->get()
                    ->toArray();
        return $res;
    }
}


